﻿/// <summary>
/// 功能：
/// 作者：chao.jiang
/// 日期：2012/9/26 17:06:10
/// 备注：
/// 修改：
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Phoenix.Service
{
    public class CommService
    {
        //static ILogService logService = new LogService();

        /// <summary>
        /// 获取中文星期几
        /// </summary>
        /// <param name="dayOfWeek"></param>
        /// <returns></returns>
        public static string GetChineseDayOfWeek(string dayOfWeek)
        {
            string chineseDayOfWeek = "";

            switch (dayOfWeek)
            {
                case "Sunday":
                    chineseDayOfWeek = "星期日";
                    break;

                case "Monday":
                    chineseDayOfWeek = "星期一";
                    break;

                case "Tuesday":
                    chineseDayOfWeek = "星期二";
                    break;

                case "Wednesday":
                    chineseDayOfWeek = "星期三";
                    break;

                case "Thursday":
                    chineseDayOfWeek = "星期四";
                    break;

                case "Friday":
                    chineseDayOfWeek = "星期五";
                    break;

                case "Saturday":
                    chineseDayOfWeek = "星期六";
                    break;

                default:
                    break;

            }
            return chineseDayOfWeek;
        }

        /// <summary>
        /// 操作日志
        /// </summary>
        /// <param name="logModule">操作模块</param>
        /// <param name="logType">操作类型</param>
        /// <param name="text">操作内容</param>
        public static void AddLog(string logModule, string logType, string text)
        {
            //Log log = new Log();
            //log.LogID = Guid.NewGuid();
            //log.LoginNo = CurrentContextService.Current.Account.LoginNo;
            //log.UserName = CurrentContextService.Current.Account.UserName;
            //log.AccountID = CurrentContextService.Current.Account.AccountID.ToString();
            //log.LogTime = DateTime.Now;
            //log.LogTag = logType + "[" + text + "]";
            //log.LogType = logType;
            //log.LogModule = logModule;
            //logService.Add(log);
        }

        /// <summary>
        /// md5加密
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string md5(string value)
        {
            byte[] data = Encoding.GetEncoding("GB2312").GetBytes(value);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] OutBytes = md5.ComputeHash(data);

            string OutString = "";
            for (int i = 0; i < OutBytes.Length; i++)
            {
                OutString += OutBytes[i].ToString("x2");
            }
            return OutString.ToUpper();
        }

        /// <summary>
        /// 提示并刷新父页
        /// </summary>
        /// <param name="alertText"></param>
        /// <returns></returns>
        public static string JsAlertAndParentReload(string alertText)
        {
            string script = "<script>alert('" + alertText + "');parent.toppage.window.document.forms[0].submit()</script>";
            return script;
        }

        public static string JsAlertAndBlankParentReload(string alertText)
        {
            string script = "<script>alert('" + alertText + "');parent.toppage.window.location.reload()</script>";
            return script;
        }

        /// <summary>
        /// 提示并转到指定Action
        /// </summary>
        /// <param name="alertText"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static string JsAlertAndRedirect(string alertText, string action)
        {
            string script = "<script>alert('" + alertText + "');parent.toppage.window.location='" + action + "'</script>";

            return script;
        }

        /// <summary>
        /// 转到指定Action
        /// </summary>
        /// <param name="alertText"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static string JsRedirect()
        {
            string script = "<script>window.location.reload();</script>";

            return script;
        }

        public static string JsAlertAndReload(string alertText, string action)
        {
            string script = "<script>alert('" + alertText + "');window.location='" + action + "'</script>";

            return script;
        }

        public static string JsAlertAndGoHis(string alertText)
        {
            string script = "<script>alert('" + alertText + "');window.history.go(-1);</script>";

            return script;
        }

        // 提示并让父页 重新执行 Query, 而非reload(), binxiao
        public static string JsAlertBlankParentReQuery(string alertText)
        {
            string script = "<script>alert('" + alertText + "');window.top.oWin.document.forms[0].submit();window.top.oDG.cancel();</script>";
            return script;
        }

        // 提示并让父页 重新执行 Query, 而非reload(), binxiao
        public static string JsAlertParentReQuery(string alertText)
        {
            string script = "<script>alert('" + alertText + "');parent.toppage.window.document.forms[0].submit()</script>";
            return script;
        }

        /// <summary>
        /// 陈炎明 提交失败时关闭窗口
        /// </summary>
        /// <param name="alertText"></param>
        /// <returns></returns>
        public static string JsAlertAndCloseWindow(string alertText)
        {
            string script = "<script>alert('" + alertText + "');window.top.oDG.cancel();</script>";

            return script;
        }

        /// <summary>
        /// 陈炎明 提交失败时弹出提示
        /// </summary>
        /// <param name="alertText"></param>
        /// <returns></returns>
        public static string JsAlert(string alertText)
        {
            string script = "<script>alert('" + alertText + "');</script>";

            return script;
        }

        /// <summary>
        /// 添加组织架构成功后刷新Frame
        /// 陈炎明
        /// </summary>
        /// <param name="alertText">提示消息</param>
        /// <returns></returns>
        public static string JsAlertAndReloadFrame(string alertText)
        {
            string script = "<script>alert('" + alertText + "');window.top.oWin.location.reload(); window.top.oDG.cancel();</script>";

            return script;
        }

        /// <summary>
        /// 提示并刷新父页
        /// </summary>
        /// <param name="alertText"></param>
        /// <returns></returns>
        public static string JsAlertAndParentPara(string alertText, string url)
        {
            string script = "<script>alert('" + alertText + "');parent.toppage.window.location='" + url + "'</script>";

            return script;
        }


    }

}
